#include "./head/mainwindow.h"
#include "ui_mainwindow.h"

#include <ctime>
#include <cstdlib>

void MainWindow::on_nextButton_clicked()
{
    srand((time_t)time(NULL));

    // 获取当前行
    int currentRow = ui->musicList->currentRow();

    // 下一行
    int nextRow = 0;
    if (mode == Order_Mode)
    {
        nextRow = (currentRow + 1) % ui->musicList->count();
    }
    else if (mode == Random_Mode)
    {
        if (ui->musicList->count() >= 3)
        {
            do
            {
                nextRow = rand() % ui->musicList->count();
            }
            while (nextRow == currentRow);
        }
        else if (ui->musicList->count() == 2)
        {
            nextRow = currentRow == 1 ? 0 : 1;
        }
        else if (ui->musicList->count() == 1)
        {
            nextRow = currentRow;
        }
    }
    else if (mode == Circle_Mode)
    {
        nextRow = currentRow;
    }

    ui->musicList->setCurrentRow(nextRow);

    startPlayMusic();
}
